package com.ashye.kotlinversion

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private val adapter: FooterBindingRecyclerAdapter<String> by lazy { FooterBindingRecyclerAdapter<String>(R.layout.binding_recycler_item, BR.itemData) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initRecyclerView()
        initFab()
    }

    private fun initRecyclerView() {
        recyclerview.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        recyclerview.itemAnimator = DefaultItemAnimator()
        recyclerview.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
        recyclerview.adapter = adapter
        adapter.setOnItemClicked { v, i, item ->
            println("i: ${i}, item: ${item}")
        }
    }

    private fun initFab() {
        fab.setOnClickListener {
            adapter.addData("ssssssss=${adapter.itemCount}")

            fab.postDelayed(Runnable { adapter.loading(true) }, 3000)
            fab.postDelayed(Runnable { adapter.loadAll() }, 6000)
            fab.postDelayed(Runnable { adapter.hideFooter() }, 9000)
            fab.postDelayed(Runnable { adapter.loading(false) }, 12000)
        }
    }
}
